package com.by.controller;


import com.by.entity.User;
import com.by.result.Result;
import com.by.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1")
public class UserController {

    @Autowired
    private UserService userService;


    @PostMapping("/user")
    public Result save(@Validated @RequestBody User user, BindingResult result) {
//        V.validate(result);
        boolean rs = userService.save(user);
        return rs ? Result.success("保存成功") : Result.error(500, "保存失败");
    }

}
